# See LICENSE file for copyright and license details.

include config.mk

SRC = rid_hex.c
OBJ = $(SRC:.c=.o)

LIB = librid_hex.a
INC = rid_hex.h

.PHONY: all install uninstall clean

PKG_STR = "\nIf this is a local install you may need to run:\n\t\
\"export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig\" \nto use this library.\n"

all: $(LIB) rid_hex.3.gz

$(LIB): $(OBJ)
	@$(AR) -rcs $@ $(OBJ)

.c.o:
	@$(CC) $(CFLAGS) -c $<

rid_hex.3.gz: rid_hex.3
	@gzip -k rid_hex.3

install: $(LIB) $(INC) rid_hex.3.gz rid_hex.pc
	@echo @ install librid_hex to $(PREFIX)
	@mkdir -p $(PREFIX)/lib
	@cp $(LIB) $(PREFIX)/lib/
	@echo @ install rid_hex.h to $(PREFIX)
	@mkdir -p $(PREFIX)/include
	@cp $(INC) $(PREFIX)/include/
	@echo @ install rid_hex.3 to $(PREFIX)
	@mkdir -p $(PREFIX)/share/man/man3
	@cp rid_hex.3.gz $(PREFIX)/share/man/man3/
	@mandb -q -p
	@echo @ install rid_hex.pc to $(PREFIX)
	@printf $(PKG_STR)
	@mkdir -p $(PREFIX)/lib/pkgconfig
	@cp rid_hex.pc $(PREFIX)/lib/pkgconfig/

uninstall:
	@echo @ uninstall rid_hex from $(PREFIX)
	@rm -f $(PREFIX)/lib/$(LIB)
	@rm -f $(PREFIX)/include/$(INC)
	@rm -f $(PREFIX)/share/man/man3/rid_hex.3.gz
	@rm -f $(PREFIX)/lib/pkgconfig/rid_hex.pc

clean:
	@rm -f $(LIB) $(OBJ) rid_hex.3.gz
